home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / tp84.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  310 lines

  1. /***************************************************************************
  2.  
  3.     vidhrdw.c
  4.  
  5.     Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *tp84_videoram2;
  15. unsigned char *tp84_colorram2;
  16. static struct osd_bitmap *tmpbitmap2;
  17. static unsigned char *dirtybuffer2;
  18.  
  19. unsigned char *tp84_scrollx;
  20. unsigned char *tp84_scrolly;
  21.  
  22. int col0;
  23.  
  24.  
  25.  
  26.  
  27. static struct rectangle topvisiblearea =
  28. {
  29.     0*8, 2*8-1,
  30.     2*8, 30*8-1
  31. };
  32. static struct rectangle bottomvisiblearea =
  33. {
  34.     30*8, 32*8-1,
  35.     2*8, 30*8-1
  36. };
  37.  
  38.  
  39.  
  40. /*
  41. -The colortable is divided in 2 part:
  42.  -The characters colors
  43.  -The sprites colors
  44.  
  45. -The characters colors are indexed like this:
  46.  -2 bits from the characters
  47.  -4 bits from the attribute in colorram
  48.  -2 bits from col0 (d3-d4)
  49.  -3 bits from col0 (d0-d1-d2)
  50. -So, there is 2048 bytes for the characters
  51.  
  52. -The sprites colors are indexed like this:
  53.  -4 bits from the sprites (16 colors)
  54.  -4 bits from the attribute of the sprites
  55.  -3 bits from col0 (d0-d1-d2)
  56. -So, there is 2048 bytes for the sprites
  57.  
  58. */
  59. /*
  60.      The RGB signals are generated by 3 proms 256X4 (prom 2C, 2D and 1E)
  61.         The resistors values are:
  62.             1K  ohm
  63.             470 ohm
  64.             220 ohm
  65.             100 ohm
  66. */
  67. void tp84_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  68. {
  69.     int i;
  70.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  71.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  72.  
  73.  
  74.     for (i = 0;i < Machine->drv->total_colors;i++)
  75.     {
  76.         int bit0,bit1,bit2,bit3;
  77.  
  78.         /* red component */
  79.         bit0 = (color_prom[0] >> 0) & 0x01;
  80.         bit1 = (color_prom[0] >> 1) & 0x01;
  81.         bit2 = (color_prom[0] >> 2) & 0x01;
  82.         bit3 = (color_prom[0] >> 3) & 0x01;
  83.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  84.         /* green component */
  85.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  86.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  87.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  88.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  89.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  90.         /* blue component */
  91.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  92.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  93.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  94.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  95.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x42 * bit2 + 0x90 * bit3;
  96.  
  97.         color_prom++;
  98.     }
  99.  
  100.     color_prom += 2*Machine->drv->total_colors;
  101.     /* color_prom now points to the beginning of the lookup table */
  102.  
  103.  
  104.     /* characters use colors 128-255 */
  105.     for (i = 0;i < TOTAL_COLORS(0)/8;i++)
  106.     {
  107.         int j;
  108.  
  109.  
  110.         for (j = 0;j < 8;j++)
  111.             COLOR(0,i+256*j) = *color_prom + 128 + 16*j;
  112.  
  113.         color_prom++;
  114.     }
  115.  
  116.     /* sprites use colors 0-127 */
  117.     for (i = 0;i < TOTAL_COLORS(1)/8;i++)
  118.     {
  119.         int j;
  120.  
  121.  
  122.         for (j = 0;j < 8;j++)
  123.         {
  124.             if (*color_prom) COLOR(1,i+256*j) = *color_prom + 16*j;
  125.             else COLOR(1,i+256*j) = 0;    /* preserve transparency */
  126.         }
  127.  
  128.         color_prom++;
  129.     }
  130. }
  131.  
  132.  
  133.  
  134. /***************************************************************************
  135.  
  136.   Start the video hardware emulation.
  137.  
  138. ***************************************************************************/
  139. int tp84_vh_start(void)
  140. {
  141.     if (generic_vh_start() != 0)
  142.         return 1;
  143.  
  144.     if ((dirtybuffer2 = malloc(videoram_size)) == 0)
  145.     {
  146.         generic_vh_stop();
  147.         return 1;
  148.     }
  149.     memset(dirtybuffer2,1,videoram_size);
  150.  
  151.     if ((tmpbitmap2 = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  152.     {
  153.         free(dirtybuffer2);
  154.         generic_vh_stop();
  155.         return 1;
  156.     }
  157.  
  158.     return 0;
  159. }
  160.  
  161.  
  162.  
  163. /***************************************************************************
  164.  
  165.   Stop the video hardware emulation.
  166.  
  167. ***************************************************************************/
  168. void tp84_vh_stop(void)
  169. {
  170.     free(dirtybuffer2);
  171.     osd_free_bitmap(tmpbitmap2);
  172.     generic_vh_stop();
  173. }
  174.  
  175.  
  176.  
  177. WRITE_HANDLER( tp84_videoram2_w )
  178. {
  179.     if (tp84_videoram2[offset] != data)
  180.     {
  181.         dirtybuffer2[offset] = 1;
  182.  
  183.         tp84_videoram2[offset] = data;
  184.     }
  185. }
  186.  
  187.  
  188.  
  189. WRITE_HANDLER( tp84_colorram2_w )
  190. {
  191.     if (tp84_colorram2[offset] != data)
  192.     {
  193.         dirtybuffer2[offset] = 1;
  194.  
  195.         tp84_colorram2[offset] = data;
  196.     }
  197. }
  198.  
  199.  
  200.  
  201. /*****
  202.   col0 is a register to index the color Proms
  203. *****/
  204. WRITE_HANDLER( tp84_col0_w )
  205. {
  206.     if(col0 != data)
  207.     {
  208.         col0 = data;
  209.  
  210.         memset(dirtybuffer,1,videoram_size);
  211.         memset(dirtybuffer2,1,videoram_size);
  212.     }
  213. }
  214.  
  215.  
  216.  
  217. /***************************************************************************
  218.  
  219.     Draw the game screen in the given osd_bitmap.
  220.     Do NOT call osd_update_display() from this function, it will be called by
  221.     the main emulation engine.
  222.  
  223. ***************************************************************************/
  224. void tp84_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  225. {
  226.     int offs;
  227.     int coloffset;
  228.  
  229.  
  230.     coloffset = ((col0&0x18) << 1) + ((col0&0x07) << 6);
  231.  
  232.     for (offs = videoram_size - 1;offs >= 0;offs--)
  233.     {
  234.         if (dirtybuffer[offs])
  235.         {
  236.             int sx,sy;
  237.  
  238.  
  239.             dirtybuffer[offs] = 0;
  240.  
  241.             sx = offs % 32;
  242.             sy = offs / 32;
  243.  
  244.             drawgfx(tmpbitmap,Machine->gfx[0],
  245.                     videoram[offs] + ((colorram[offs] & 0x30) << 4),
  246.                     (colorram[offs] & 0x0f) + coloffset,
  247.                     colorram[offs] & 0x40,colorram[offs] & 0x80,
  248.                     8*sx,8*sy,
  249.                     0,TRANSPARENCY_NONE,0);
  250.         }
  251.  
  252.         if (dirtybuffer2[offs])
  253.         {
  254.             int sx,sy;
  255.  
  256.  
  257.             dirtybuffer2[offs] = 0;
  258.  
  259.             sx = offs % 32;
  260.             sy = offs / 32;
  261.  
  262.         /* Skip the middle of the screen, this ram seem to be used as normal ram. */
  263.             if (sx < 2 || sx >= 30)
  264.                 drawgfx(tmpbitmap2,Machine->gfx[0],
  265.                         tp84_videoram2[offs] + ((tp84_colorram2[offs] & 0x30) << 4),
  266.                         (tp84_colorram2[offs] & 0x0f) + coloffset,
  267.                         tp84_colorram2[offs] & 0x40,tp84_colorram2[offs] & 0x80,
  268.                         8*sx,8*sy,
  269.                         &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  270.         }
  271.     }
  272.  
  273.  
  274.     /* copy the temporary bitmap to the screen */
  275.     {
  276.         int scrollx,scrolly;
  277.  
  278.  
  279.         scrollx = -*tp84_scrollx;
  280.         scrolly = -*tp84_scrolly;
  281.  
  282.         copyscrollbitmap(bitmap,tmpbitmap,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  283.     }
  284.  
  285.     /* Draw the sprites. */
  286.     coloffset = ((col0&0x07) << 4);
  287.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  288.     {
  289.         int sx,sy,flipx,flipy;
  290.  
  291.  
  292.         sx = spriteram[offs + 0];
  293.         sy = 240-spriteram[offs + 3];
  294.         flipx = !(spriteram[offs + 2] & 0x40);
  295.         flipy = spriteram[offs + 2] & 0x80;
  296.  
  297.         drawgfx(bitmap,Machine->gfx[1],
  298.                 spriteram[offs + 1],
  299.                 (spriteram[offs + 2] & 0x0f) + coloffset,
  300.                 flipx,flipy,
  301.                 sx,sy,
  302.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  303.     }
  304.  
  305.  
  306.     /* Copy the frontmost playfield. */
  307.     copybitmap(bitmap,tmpbitmap2,0,0,0,0,&topvisiblearea,TRANSPARENCY_NONE,0);
  308.     copybitmap(bitmap,tmpbitmap2,0,0,0,0,&bottomvisiblearea,TRANSPARENCY_NONE,0);
  309. }
  310.